<html>
<!-- =====================================================================

  File:      DBO.ConvertCurrency.htm for Adventure Works Cycles Storefront Sample
  Summary:   Self-documentation for application
  Date:	     August 12, 2003

=====================================================================

  This file is part of the Microsoft SQL Server Code Samples.
  Copyright (C) 2003 Microsoft Corporation.  All rights reserved.

This source code is intended only as a supplement to Microsoft
Development Tools and/or on-line documentation.  See these other
materials for detailed information regarding Microsoft code samples.

THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

======================================================= -->
    <head>
        <title>Adventure Works Cycles Store Documentation</title>
        <link rel="stylesheet" href="style.css">
    </head>
    <body>
        <h1>"ConvertCurrency" User Defined Function</h1>

        <b>Description:</b>

        <p>This user defined function converts an amount of money in US Dollars into an equivalent amount of money
        in the specified culture's monetary system.  This equivalent amount and form of money is represented by the 
        <a href="Currency.htm">Currency</a> user defined type which is based on the <a href="Currency_cs.htm">Currency</a>&nbsp; 
        managed class.  This user defined function is based on the <a href="CurrencyConverter_cs.htm">ConvertCurrency</a>&nbsp; 
        managed method.  Both the class and the method are stored the database server as the 
        <a href="[StoreServerComponents].htm">StoreServerComponents</a>&nbsp; assembly.</p>
        <p>
        If the currency conversion cannot occur because there is insufficient data in the database to perform the currency
        conversion, then the specified amount is returned in the form of US Dollars.</p>
        
        <p><b>Note:</b>  A highly simplified algorithm is used to convert from US dollars to a different currency.  Realistic 
        currency conversion algorithms are much more complex, and beyond the scope of this sample.</p>

        <b>Definition:</b>

<pre style="background-color:white">
<font color="#0000FF"><strong>CREATE</strong></font> <font color="#0000FF"><strong>FUNCTION</strong></font> DBO.ConvertCurrency
<font color="4444FF">(</font>
	@fromAmount <font color="#0000FF"><strong>AS</strong></font> money<font color="4444FF">,</font>
	@toCultureName <font color="#0000FF"><strong>AS</strong></font> <font color="#2040a0"><strong>nvarchar</strong></font><font color="4444FF">(</font>10<font color="4444FF">)</font>
<font color="4444FF">)</font>
<font color="#0000FF"><strong>RETURNS</strong></font> Currency
<font color="#0000FF"><strong>AS</strong></font> <font color="#0000FF"><strong>EXTERNAL</strong></font> <font color="#0000FF"><strong>NAME</strong></font> [ConversionFunction]<font color="4444FF">:</font>[Microsoft.Samples.SqlServer.CurrencyConverter]<font color="4444FF">:</font><font color="4444FF">:</font>ConvertCurrency

</pre>

        <b>Database Tables Used: </b>

        <P><i>CurrencyRate:</i> &nbsp;The CurrencyRate table contains exchange rates between one 
        currency and another.  The exchange rates are for specific times and dates.
        </P>
        
    </body>
</html>
